'use strict';
const repos = require('../data/data.json');
const fs = require('fs');
const path = require('path');

module.exports = {
  store() {
    fs.writeFileSync(
      path.resolve(__dirname, '../data/data.json'),
      JSON.stringify(repos)
    );
  },
  get(index) {
    return repos[index];
  },
  getList() {
    return repos;
  },
  add(obj) {
    repos.push(obj);
    this.store();
  },
  del(index) {
    repos.splice(index, 1);
    this.store();
  },
  update(index, obj) {
    repos.splice(index, 1, obj);
    this.store();
  }
};
